<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\industrytype\controller;

class Type extends \app\AdminRest
{
    protected $model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\industrytype\model\Type();
    }
    public function typeList()
    {
        $this->model->initData($this->_uniacid);
        $input = $this->_param;
        $dis[] = ["uniacid", "=", $this->_uniacid];
        $dis[] = ["status", ">", -1];
        if(!empty($input["title"])) {
            $dis[] = ["title", "like", "%" . $input["title"] . "%"];
        }
        $data = $this->model->dataList($dis, $input["limit"]);
        return $this->success($data);
    }
    public function typeSelect()
    {
        $this->model->initData($this->_uniacid);
        $input = $this->_param;
        $dis[] = ["uniacid", "=", $this->_uniacid];
        if(isset($input["status"])) {
            $dis[] = ["status", "=", $input["status"]];
        } else {
            $dis[] = ["status", "=", 1];
        }
        if(!empty($input["title"])) {
            $dis[] = ["title", "like", "%" . $input["title"] . "%"];
        }
        $data = $this->model->where($dis)->order("top desc,id desc")->select()->toArray();
        return $this->success($data);
    }
    public function typeAdd()
    {
        $input = $this->_input;
        $input["uniacid"] = $this->_uniacid;
        $data = $this->model->dataAdd($input);
        return $this->success($data);
    }
    public function typeInfo()
    {
        $input = $this->_param;
        $dis = ["id" => $input["id"]];
        $data = $this->model->dataInfo($dis);
        return $this->success($data);
    }
    public function typeUpdate()
    {
        $input = $this->_input;
        $dis = ["id" => $input["id"]];
        if(isset($input["status"]) && in_array($input["status"], [0, -1])) {
            $coach_model = new \app\massage\model\Coach();
            $service_model = new \app\massage\model\Service();
            $find = $coach_model->where(["industry_type" => $input["id"]])->where("status", "in", [1, 2, 3])->find();
            if(!empty($find)) {
                $attendant_name = getConfigSetting($this->_uniacid, "attendant_name");
                return $this->error("有" . $attendant_name . "正在使用该类型");
            }
            $find = $service_model->where(["industry_type" => $input["id"]])->where("status", ">", -1)->find();
            if(!empty($find)) {
                return $this->error("有服务正在使用该类型");
            }
        }
        if(isset($input["index_show"]) && $input["index_show"] == 1) {
            $count = $this->model->where("id", "<>", $input["id"])->where(["index_show" => 1])->count();
            if(3 <= $count) {
                return $this->error("首页推荐最多3个");
            }
        }
        $data = $this->model->dataUpdate($dis, $input);
        return $this->success($data);
    }
}

?>